package com.firmail.service;

import com.firmail.exception.FieldValidationException;
import org.springframework.stereotype.Service;
import org.xml.sax.InputSource;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;

@Service
public class CheckDataFormatService {

	/**
	 * 校验是不是xml文件
	 * 
	 * @return
	 */
	public boolean checkXML(String dataContent) {
		try {
			DocumentBuilderFactory foctory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = foctory.newDocumentBuilder();
			builder.parse(new InputSource(new StringReader(dataContent)));
			return true;
		} catch (Exception e) {
			throw new FieldValidationException(e);
		}
	}

}
